<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="县区" prop="city" v-show="cityShow">
        <el-select
          v-model="queryParams.city"
          clearable
          placeholder="请选择"
          size="small"
          @change="selectCity"
        >
          <el-option
            v-for="item in this.cityData"
            :key="item.deptCode"
            :label="item.deptName"
            :value="item.deptCode"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="乡镇" prop="town" v-show="townShow">
        <el-select
          v-model="queryParams.town"
          clearable
          placeholder="请选择"
          size="small"
          @change="selectTown"
        >
          <el-option
            v-for="item in this.townData"
            :key="item.deptCode"
            :label="item.deptName"
            :value="item.deptCode"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="村" prop="village" v-show="villageShow">
        <el-select
          v-model="queryParams.village"
          clearable
          placeholder="请选择"
          size="small"
          @change="selectVillage"
        >
          <el-option
            v-for="item in this.villageData"
            :key="item.deptCode"
            :label="item.deptName"
            :value="item.deptCode"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="附着物类型" prop="evaItemKey">
        <el-select
          v-model="queryParams.evaItemKey"
          clearable
          placeholder="请选择"
          size="small"
        >
          <el-option
            v-for="item in this.EvaluationList"
            :key="item.itemKey"
            :label="item.itemName"
            :value="item.itemKey"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="承包方名称" prop="cbfmc">
        <el-input
          v-model="queryParams.cbfmc"
          placeholder="请输入承包方名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退耕年份" prop="tyear">
        <el-date-picker
          v-model="queryParams.tyear"
          value-format="yyyy"
          type="year"
          placeholder="选择退耕年份"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否作废" prop="by2">
        <el-select
          v-model="queryParams.by2"
          clearable
          placeholder="请选择"
          size="small"
          @change="selectnullify"
        >
          <el-option
            v-for="item in this.nullifyData"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ownership:dk:remove']"
          >删除
        </el-button>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="DKList"
      @selection-change="handleSelectionChange"
      :row-class-name="rowStyle"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        width="220"
        label="行政区划"
        align="center"
        prop="county"
      >
        <template slot-scope="scope">
          {{ scope.row.county }} - {{ scope.row.township }} -
          {{ scope.row.village }}
        </template>
      </el-table-column>
      <el-table-column
        label="地块编码"
        align="center"
        min-width="180"
        prop="dkbm"
      />
      <!-- <el-table-column label="县区" width="120" align="center" prop="county"/>
       <el-table-column label="乡镇" width="120" align="center" prop="township"/>
       <el-table-column label="村" width="150" align="center" prop="village"/>-->
      <el-table-column
        label="承包方名称"
        min-width="200"
        align="center"
        prop="cbfmc"
      />
      <el-table-column label="退耕年份" align="center" prop="tyear" />
      <el-table-column
        label="面积（亩）"
        min-width="100"
        align="center"
        prop="scmjm"
      />
      <el-table-column
        label="土地性质"
        min-width="150"
        align="center"
        prop="dksx"
      />
      <el-table-column label="附着物" min-width="200" align="center">
        <template slot-scope="scope">
          <div
            v-for="(item, index) in scope.row.compItems"
            :key="index"
            style="text-align: center"
          >
            {{
              item.compensationType == "0" || item.compensationType == "2"
                ? item.evaluationItemName
                : ""
            }}
            <!--            {{ item.evaluationItemName}} {{item.compensationType}}-->
          </div>
          <!-- <div v-for="item in scope.row.compItems" style="text-align: center;">
             <span v-if="item.compensationType=='0'">{{ item.evaluationItemName }}</span>
           </div>-->
          <!-- <div v-if="scope.row.compItems.length<2" style="text-align: center;">
            <div v-for="item in scope.row.compItems" style="text-align: center;">
              {{ item.compensationType=='0'?item.evaluationItemName:'' }}
            </div>
          </div>
          <div v-else style="text-align: center;">
            <div v-for="item in scope.row.compItems" style="text-align: center;">
              <span v-if="item.compensationType=='0'">{{ item.evaluationItemName }}</span>
            </div>
          </div>-->
        </template>
      </el-table-column>
      <el-table-column
        label="地块名称"
        width="100"
        align="center"
        prop="dkmc"
      />
      <el-table-column
        label="原地块编码"
        min-width="150"
        align="center"
        prop="by4"
      />
      <el-table-column
        label="原地块面积"
        min-width="150"
        align="center"
        prop="parentDkmjm"
      />
      <el-table-column
        label="变更年份"
        min-width="150"
        align="center"
        prop="parentYear"
      />
      <el-table-column
        label="备注"
        min-width="150"
        align="center"
        prop="remark"
      />
      <el-table-column
        fixed="right"
        label="操作"
        width="170"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            :disabled="scope.row.by2 == 1"
            :class="scope.row.by2 == 1 ? 'zuofei' : ''"
            v-hasPermi="['ownership:dk:remove']"
            >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            :disabled="scope.row.by2 == 1"
            :class="scope.row.by2 == 1 ? 'zuofei' : ''"
            v-hasPermi="['ownership:dk:remove']"
            >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleFzw(scope.row)"
            v-hasPermi="['ownership:dk:query']"
          >
            <svg-icon class="svg" icon-class="botany" />
            明细信息
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-delete"
            @click="handlecancel(scope.row)"
            v-if="scope.row.by2 != 1"
            v-hasPermi="['ownership:dk:query']"
          >
            作废
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-delete"
            @click="handlecancel(scope.row)"
            v-else
            disabled
            style="color: #a3a3a3"
            v-hasPermi="['ownership:dk:query']"
          >
            已作废
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      :title="title"
      :visible.sync="open"
      width="900px"
      append-to-body
      @close="cancel"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="95px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="地块编码" prop="jfmc">
              <el-input
                v-model="form.dkbm"
                placeholder="请输入地块编码"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地块名称" prop="dkmc">
              <el-input v-model="form.dkmc" placeholder="请输入地块名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="实测面积" prop="scmjm">
              <el-input
                v-model="form.scmjm"
                placeholder="请输入实测面积"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地块属性" prop="dksx">
              <el-input
                v-model="form.dksx"
                placeholder="请输入地块属性"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="地块位置" prop="dkwz">
              <el-input v-model="form.dkwz" placeholder="请输入地块位置" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="东至" prop="dz">
              <el-input v-model="form.dz" placeholder="请输入东至" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="西至" prop="xz">
              <el-input v-model="form.xz" placeholder="请输入西至" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="南至" prop="nz">
              <el-input v-model="form.nz" placeholder="请输入南至" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="北至" prop="bz">
              <el-input v-model="form.bz" placeholder="请输入北至" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="原地块编码" prop="by4">
              <el-select
                v-model="form.by4"
                multiple
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in DKLists"
                  :key="item.dkbm"
                  :label="item.dkbm"
                  :value="item.dkbm"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input
            type="textarea"
            v-model="form.remark"
            placeholder="请输入备注"
          />
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="pgList" ref="pgTable">
        <el-table-column
          label="类别"
          align="center"
          prop="compensationType"
          :formatter="compensationtypeFormat"
        />
        <el-table-column
          label="评估项"
          align="center"
          prop="evaluationItemName"
        />
        <el-table-column
          label="面积（亩）"
          align="center"
          prop="evaluationArea"
        >
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.evaluationArea"
              placeholder="请输入评估金额"
              @blur="updateArea(scope.row)"
              @input="searchArea($event)"
              @keyup.enter="searchArea"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="单价（元）"
          align="center"
          prop="evaluationItemPrice"
        >
          <template slot-scope="scope">
            {{
              scope.row.evaluationItemPrice == 0
                ? "-"
                : String(scope.row.evaluationItemPrice)
                    .replace(/(\d)(?=(?:\d{3})+$)/g, "$1,")
                    .split(".").length < 2
                ? String(scope.row.evaluationItemPrice).replace(
                    /(\d)(?=(?:\d{3})+$)/g,
                    "$1,"
                  ) + ".00"
                : String(scope.row.evaluationItemPrice).replace(
                    /(\d)(?=(?:\d{3})+$)/g,
                    "$1,"
                  )
            }}
          </template>
        </el-table-column>
        <el-table-column label="评估价格（元）" align="center" prop="price">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.price"
              placeholder="请输入评估价格"
              @blur="updatePrice(scope.row)"
              @input="searchPrice($event)"
              @keyup.enter="searchPrice"
            />
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
           <template slot-scope="scope">
             <el-button
               size="mini"
               type="text"
               icon="el-icon-delete"
               @click="handleDelete(scope.row)"
               v-hasPermi="['compensation:item:remove']"
             >删除
             </el-button>
           </template>
         </el-table-column>-->
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="title"
      :visible.sync="opendetails"
      width="900px"
      append-to-body
      @close="cancel"
    >
      <div style="min-height: 400px">
        <el-table v-loading="loading" :data="pgList" ref="pgTable">
          <el-table-column
            label="类别"
            align="center"
            prop="compensationType"
            :formatter="compensationtypeFormat"
          />
          <el-table-column
            label="评估项"
            align="center"
            prop="evaluationItemName"
          />
          <el-table-column
            label="面积（亩）"
            align="center"
            prop="evaluationArea"
          />
          <el-table-column
            label="单价（元）"
            align="center"
            prop="evaluationItemPrice"
          >
            <template slot-scope="scope">
              {{
                scope.row.evaluationItemPrice == 0
                  ? "-"
                  : String(scope.row.evaluationItemPrice)
                      .replace(/(\d)(?=(?:\d{3})+$)/g, "$1,")
                      .split(".").length < 2
                  ? String(scope.row.evaluationItemPrice).replace(
                      /(\d)(?=(?:\d{3})+$)/g,
                      "$1,"
                    ) + ".00"
                  : String(scope.row.evaluationItemPrice).replace(
                      /(\d)(?=(?:\d{3})+$)/g,
                      "$1,"
                    )
              }}
            </template>
          </el-table-column>
          <el-table-column label="评估价格（元）" align="center" prop="price">
            <template slot-scope="scope">
              {{
                scope.row.price == 0
                  ? "-"
                  : String(scope.row.price)
                      .replace(/(\d)(?=(?:\d{3})+$)/g, "$1,")
                      .split(".").length < 2
                  ? String(scope.row.price).replace(
                      /(\d)(?=(?:\d{3})+$)/g,
                      "$1,"
                    ) + ".00"
                  : String(scope.row.price).replace(
                      /(\d)(?=(?:\d{3})+$)/g,
                      "$1,"
                    )
              }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>
    </el-dialog>

    <!--<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <div style="min-height: 400px">
        <el-table v-loading="loading" :data="pgList">
          <el-table-column label="类型" align="center" prop="compensationType" :formatter="compensationtypeFormat"/>
          <el-table-column label="名称" align="center" prop="evaluationItemName"/>
          <el-table-column label="面积（亩）" align="center" prop="evaluationArea"/>
         &lt;!&ndash; <el-table-column label="单价（元）" align="center" prop="evaluationItemPrice">
            <template slot-scope="scope">
              {{ scope.row.evaluationItemPrice == 0 ? "-" : String(scope.row.evaluationItemPrice).replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') }}
            </template>
          </el-table-column>&ndash;&gt;
        &lt;!&ndash;  <el-table-column label="评估价格（元）" align="center" prop="price">
            <template slot-scope="scope">
              {{ scope.row.price == 0 ? "-" : String(scope.row.price).replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') }}
            </template>
          </el-table-column>&ndash;&gt;
          &lt;!&ndash;        <el-table-column label="补偿类型" align="center" prop="xz"/>&ndash;&gt;

        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确定</el-button>
      </div>
    </el-dialog>-->
    <!--作废  -->
    <el-dialog title="作废" :visible.sync="cancels">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="120px"
      >
        <el-form-item label="作废原因" prop="desc">
          <el-input type="textarea" v-model="ruleForm.desc"></el-input>
        </el-form-item>
        <el-form-item label="作废变更时间" prop="date">
          <el-date-picker
            v-model="ruleForm.date"
            type="date"
            placeholder="选择日期"
            format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="cancelsanniu('ruleForm')"
            >确定</el-button
          >
          <el-button @click="cancelsannius">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- Form -->
  </div>
</template>

<script>
import {
  addDK,
  delDK,
  exportDK,
  getDK,
  listDK,
  updateDK,
  cancelsDK,
} from "@/api/chgl/dk";
import { childlistUse } from "@/api/system/dept";
import { getEvaluationAccountingItem } from "@/api/pggl/evaluationAccounting";
import { getInfo } from "@/api/login";
import { listEvaluation } from "@/api/pggl/evaluation";
import { updateItem } from "@/api/information/item";
import Template from "@/views/message/template/index";

export default {
  name: "DK",
  components: { Template },
  data() {
    return {
      options: [
        {
          value: "选项1",
          label: "黄金糕",
        },
        {
          value: "选项2",
          label: "双皮奶",
        },
        {
          value: "选项3",
          label: "蚵仔煎",
        },
        {
          value: "选项4",
          label: "龙须面",
        },
        {
          value: "选项5",
          label: "北京烤鸭",
        },
      ],
      value1: [],
      // 遮罩层
      loading: false,
      // 选中数组
      compensationtype: [],
      ids: [],
      city: "",
      town: "",
      village: "",
      by2: "",
      cityShow: "",
      townShow: "",
      villageShow: "",
      cityData: [],
      townData: [],
      villageData: [],
      EvaluationList: [],
      currentPrice: 0,
      currentArea: 0,
      pgList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      DKList: [
        {
          xian: "安新县",
          zhen: "三台镇",
          cun: "山西村",
          cbfmc: "李斯",
          dkbm: "130638000000000001",
          mj: "12.51",
          tdxz: "集体",
        },
      ],
      DKLists: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      opendetails: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dkId: null,
        objectid: null,
        evaItemKey: null,
        bsm: null,
        ysdm: null,
        dkbm: null,
        dkmc: null,
        syqxz: null,
        dklb: null,
        tdlylx: null,
        dldj: null,
        tdyt: null,
        sfjbnt: null,
        scmj: null,
        dkdz: null,
        dkxz: null,
        dknz: null,
        dkbz: null,
        dkbzxx: null,
        zjrxm: null,
        shape: null,
        zzw: null,
      },
      nullifyData: [
        {
          label: "是",
          value: "1",
        },
        {
          label: "否",
          value: "0",
        },
      ],
      // 表单参数
      form: {
        by4: "",
      },
      // 表单校验
      rules: {
        id: [{ required: true, message: "种植物不能为空", trigger: "blur" }],
        objectid: [
          { required: true, message: "种植物不能为空", trigger: "blur" },
        ],
        desc: [
          { required: true, message: "作废原因不可为空", trigger: "blur" },
          { min: 1, max: 200, message: "作废原因最多200字", trigger: "change" },
        ],
        date: [
          { required: true, message: "作废原因不可为空", trigger: "blur" },
        ],
      },
      //作废
      cancels: false,
      ruleForm: {
        desc: "",
        date: "",
      },
    };
  },
  created() {
    this.getDicts("sys_evaluation_type").then((response) => {
      this.compensationtype = response.data;
    });
    this.getDicts("sys_normal_disable").then((response) => {
      this.statusOptions = response.data;
    });
    this.getList();
    getInfo().then((response) => {
      let deptCode = response.user.dept.deptCode;

      if (deptCode.length == 4) {
        //新区
        this.cityShow = true;
        this.townShow = true;
        this.villageShow = true;
        childlistUse(deptCode).then((response) => {
          this.cityData = response.data;
        });
      } else if (deptCode.length == 6) {
        //县
        this.cityShow = false;
        this.townShow = true;
        this.villageShow = true;
        childlistUse(deptCode).then((response) => {
          this.townData = response.data;
        });
      } else if (deptCode.length == 9) {
        //镇
        this.cityShow = false;
        this.townShow = false;
        this.villageShow = true;
        childlistUse(deptCode).then((response) => {
          this.villageData = response.data;
        });
      } else if (deptCode.length == 12) {
        //村
        this.cityShow = false;
        this.townShow = false;
        this.villageShow = false;
      } else {
        this.childlist(1306);
        this.cityShow = true;
        this.townShow = true;
        this.villageShow = true;
      }
    });
    //附着物信息
    listEvaluation({
      compensationType: 0,
      pageNum: 1,
      pageSize: 100,
    }).then((response) => {
      this.EvaluationList = response.rows;
    });
  },
  methods: {
    searchPrice(event) {
      this.currentPrice = event;
    },
    searchArea(event) {
      this.currentArea = event;
    },
    updatePrice(item) {
      let accountingItemId = item.accountingItemId;
      let price = this.currentPrice;
      if (
        price != "" &&
        price != undefined &&
        price != null &&
        accountingItemId != "" &&
        accountingItemId != undefined
      ) {
        updateItem({ accountingItemId: accountingItemId, price: price }).then(
          (response) => {
            if (response.code == 200) {
              this.msgSuccess("修改成功");
              this.getList();
              this.currentData = "";
            }
          }
        );
      }
    },
    updateArea(item) {
      let accountingItemId = item.accountingItemId;
      let area = this.currentArea;
      if (
        area != "" &&
        area != undefined &&
        area != null &&
        accountingItemId != "" &&
        accountingItemId != undefined
      ) {
        updateItem({
          accountingItemId: accountingItemId,
          evaluationArea: area,
        }).then((response) => {
          if (response.code == 200) {
            this.msgSuccess("修改成功");
            this.getList();
            this.currentData = "";
          } else {
            this.msgError(response.msg);
          }
        });
      }
    },
    compensationtypeFormat(row, column) {
      return this.selectDictLabel(this.compensationtype, row.compensationType);
    },
    handleFzw(row) {
      this.reset();
      const dkbm = row.dkbm || this.ids;
      this.opendetails = true;
      this.title = "明细信息";
      getEvaluationAccountingItem(dkbm).then((response) => {
        this.pgList = response.rows;
        this.loading = false;
      });
    },
    //作废
    handlecancel(row) {
      var than = this;
      console.log(row);
      than.cancelsid = row.dkId;
      than.cancels = true;
    },
    //作废按钮
    cancelsanniu(formName) {
      var than = this;
      var dates = new Date(this.ruleForm.date);
      let Y = dates.getFullYear();
      let M = dates.getMonth() + 1;
      let D = dates.getDate();
      if (M < 10) {
        M = "0" + M;
      }
      if (D < 10) {
        D = "0" + D;
      }

      let datess = Y + "-" + M + "-" + D;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let data = {
            dkId: this.cancelsid,
            by2: "1",
            by3: this.ruleForm.desc,
            by5: datess,
          };
          cancelsDK(data).then((response) => {
            console.log(response);
            this.ruleForm.desc = "";
            this.ruleForm.date = "";
            if (response.code == 200) {
              than.cancels = false;

              than.getList();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    rowStyle(row) {
      console.log(row.row.by2);
      if (row.row.by2 == "1") {
        return "yanses"
      } else {
        return ""
      }
    },
    cancelsannius() {
      this.ruleForm.desc = "";
      this.ruleForm.date = "";
    },
    childlist(deptCode) {
      childlistUse(deptCode).then((response) => {
        this.cityData = response.data;
      });
    },
    // 选择县
    selectCity(val) {
      this.city = val;
      this.queryParams.cbfbm = val;
      if (val != "" && val != null) {
        childlistUse(val).then((response) => {
          this.townData = response.data;
        });
      }
    },
    // 选择镇
    selectTown(val) {
      this.town = val;
      this.queryParams.cbfbm = val;
      if (val != "" && val != null) {
        childlistUse(val).then((response) => {
          this.villageData = response.data;
        });
      }
    },
    // 选择村
    selectVillage(val) {
      this.queryParams.cbfbm = val;
      this.village = val;
    },
    getList() {
      this.loading = true;
      listDK(this.queryParams).then((response) => {
        this.DKList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getLists() {
      this.loading = true;
      this.queryParams.by2 = "1";
      this.queryParams.pageSize = this.total;
      listDK(this.queryParams).then((response) => {
        this.DKLists = response.rows;

        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.opendetails = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        dkId: null,
        objectid: null,
        bsm: null,
        ysdm: null,
        dkbm: null,
        dkmc: null,
        dldj: null,
        tdyt: null,
        sfjbnt: null,
        scmjm: null,
        dkdz: null,
        dkxz: null,
        fzwlx: null,
        dkwz: null,
        dz: null,
        xz: null,
        nz: null,
        bz: null,
        dkbzxx: null,
        zjrxm: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.cbfbm = "";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.dkId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.getLists();
      this.reset();
      const dkId = row.dkId || this.ids;
      this.form.dkId = dkId;
      this.open = true;
      this.title = "修改";
      getDK(dkId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改";

        const dkbm = row.dkbm;
        getEvaluationAccountingItem(dkbm).then((response) => {
          this.pgList = response.rows;
          this.loading = false;
        });
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.dkId != null) {
            var a = this.form.by4.toString();
            console.log(a);
            this.form.by4 = a;
            updateDK(this.form).then((response) => {
              // this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDK(this.form).then((response) => {
              // this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.dkId || this.ids;
      this.$confirm("是否确认删除数据项?", "警告", {
        cancelButtonClass: "btn-custom-cancel",
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delDK(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportDK(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        })
        .catch(() => {});
    },
  },
};
</script>

<style>
.zuofei {
  color: #a3a3a3 !important;
}
.yanses{
   color: #cac9c9 !important;
}
</style>